package me.zhenqu.redis.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: yibing.tan
 * Date: 11-11-14
 * Time: 下午4:18
 * To change this template use File | Settings | File Templates.
 */
public abstract class CacheCoder<T> {
    public abstract byte[] encode(T o);

    public abstract T decode(byte[] val, int offset, int size);

    public T decode(byte[] val) {
        return decode(val, 0, val.length);
    }

    protected void writeBytes(ByteArrayOutputStream bos, byte[] encode) {
        try {
            bos.write(encode);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
